﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using PersonaLibrary.Data;

namespace PersonaLibrary.PersonaliiReference
{
	partial class Employee : IDBEntity
	{
		[XmlIgnore]
		public string FullName
		{
			get
			{
				if (!string.IsNullOrEmpty(Patronymic))
					return string.Concat(Surname, " ", Name, " ", Patronymic);
				if (!string.IsNullOrEmpty(Surname))
					return string.Concat(Surname, " ", Name);
				return Name;
			}
			set
			{
				string[] values = value.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
				if (values.Length >= 1)
					Surname = values[0];
				else
					Surname = null;

				if (values.Length >= 2)
					Name = values[1];
				else
					Name = null;

				if (values.Length >= 3)
					Patronymic = values[2];
				else
					Patronymic = null;
			}
		}

		[XmlIgnore]
		public string Notes
		{
			get
			{
				return string.Join(", ", EmployeeNoteLink);
			}
		}

		[XmlIgnore]
		public string MultiBirthday
		{
			get
			{
				if (Birthday.HasValue)
					return Birthday.Value.ToShortDateString();

				return InexactBirthday;
			}
			set
			{
				DateTime parseResult;
				if (DateTime.TryParse(value, out parseResult))
					Birthday = parseResult;
				else
					InexactBirthday = value;
			}
		}

		public override string ToString()
		{
			return FullName;
		}
	}
}
